package com.zhuiyun.educations.api.sysuserback.mapper;

import com.zhuiyun.educations.api.sysuserback.entiy.DTO.SysUserBackUpdatePasswordDTO;
import com.zhuiyun.educations.api.sysuserback.entiy.SysUserBack;
import com.zhuiyun.educations.api.sysuserback.entiy.vo.SysUserBackVo;
import com.zhuiyun.educations.common.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/*/**
* @Author MJL
* @Description
* @Date 2023/6/15 15:49
* @Return  * @param null
*/
@Mapper
public interface SysUserBackMapper extends BaseMapper<SysUserBack> {
    /*/**
    * @Author MJL
    * @Description todo 用户表全查
    * @Date 2023/6/15 19:45
    * @Return java.util.List<com.zhuiyun.educations.api.sysuserback.entiy.SysUserBack> * @param sysUserBack
    */
    @Select("<script> select u.id,u.user_name,u.user_login_name," +
            "u.user_password,u.user_sex," +
            "u.user_age,u.create_time," +
            "u.del_flag,r.role_name from sys_user u " +
            "inner join sys_role r on u.role_id = r.id " +
            "where u.del_flag = '0' " +
            "<when test = 'userName != &quot;&quot; and userName != null'>" +
            " and u.user_name like concat('%',#{userName},'%') </when> " +
            "<when test = 'userLoginName != &quot;&quot; and userLoginName != null'>" +
            " and u.user_login_name like concat('%',#{userLoginName},'%') </when>" +
            " </script>")
    List<SysUserBack> userList(SysUserBackVo sysUserBackVo);

    /**
    * @Author MJL
    * @Description todo 用户表添加
    * @Date 2023/6/16 9:18
    * @Return  * @param null
    */
    @Insert("insert into sys_user (user_name,user_login_name,user_password," +
            "user_sex,user_age,role_id,create_time,del_flag) values " +
            "(#{userName},#{userLoginName},#{userPassword},#{userSex}," +
            "#{userAge},#{roleId},#{createTime},#{delFlag})")
    int SysUserAdd(SysUserBack sysUserBack);

    /**
    * @Author MJL
    * @Description todo 用户表逻辑删除
    * @Date 2023/6/16 13:50
    * @Return  * @param null
    */
    @Update("update sys_user set del_flag = 1 " +
            "where id = #{id}")
    int SysUserDelete(Integer id);

    /**
    * @Author MJL
    * @Description todo 用户表修改
    * @Date 2023/6/16 14:40
    * @Return  * @param null
    */
    @Update("update sys_user set user_name = #{userName}," +
            "user_login_name = #{userLoginName},user_sex = #{userSex}," +
            "user_age = #{userAge}," +
            "update_time = #{updateTime} where id = #{id}")
    int SysUserUpdate(SysUserBack sysUserBack);

    /**
    * @Author MJL
    * @Description todo 修改密码
    * @Date 2023/7/4 10:11
    * @Return  * @param null
    */
    @Update("update sys_user set user_password = #{userPassword} where `id` = #{id}")
    Integer SysUserUpdatePassword(SysUserBackUpdatePasswordDTO sysUserBackUpdatePasswordDTO);

    /**
    * @Author MJL
    * @Description todo 用户表分配权限
    * @Date 2023/7/5 14:34
    * @Return  * @param null
    */
    @Update("update sys_user set role_id = #{roleId} where id = #{id}")
    int userAssignmentRole(SysUserBack sysUserBack);
}
